﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hr.IBLL;
using Hr.IDAL;
using Hr.DALContainer;
using Hr.Model;
using System.Data.Entity;
using Hr.DAL;

namespace Hr.BLL
{
    public partial class TaskService : BaseService<Task_List>, ITask_ListService
    {
        // 实现接口
        private ITask_ListDAL Task_ListService = Container.Resolve<ITask_ListDAL>();
        //创建EF对象
        private DbContext db = DbContextFactory.Create();

        //BLL层核心代码

        //引入DAL层
        protected TaskDAL Rdl = new TaskDAL();

        /// <summary>
        /// 获取当前登录用户的任务管理页面信息
        /// </summary>
        /// <param name="id">当前登录的用户id</param>
        /// <returns>任务列表</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/11</create>
        /// <updata>null</updata>

        public Dictionary<string, object> SendTaskList(int page, int limit, int UserId)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"TaskList",Rdl.SendTaskList(UserId).Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.SendTaskList(UserId).Count() }
            };
            return dt;
        }

        /// <summary>
        /// 根据pk_Task查询需要修改的数据
        /// </summary>
        /// <param name="id">Task_List</param>
        /// <returns>任务列表</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/9</create>
        /// <updata>null</updata>

        public Dictionary<string, object> EditSelectBinding(int pk_Task)
        {
            Task_List t= Rdl.EditSelectBinding(pk_Task);
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"TaskInfo",t },
                {"SelNameList",db.Set<User_List>().Where(n => t.UserList.ToString().Contains(n.pk_User.ToString())).Select(s=>new{ s.pk_User,s.FullName,s.UserName}) }
            };
            return dt;
        }

        /// <summary>
        /// 根据pk_Task查询需要修改的数据 查看页面
        /// </summary>
        /// <param name="id">Task_List</param>
        /// <returns>任务列表</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/20</create>
        /// <updata>null</updata>

        public object ReceiveUserTextBinding(string UserList)
        {
            return Rdl.ReceiveUserTextBinding(UserList);
        }

        /// <summary>
        /// 根据UserList查询用户姓名FullName
        /// </summary>
        /// <param name="id">FullName</param>
        /// <returns>任务列表</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/13</create>
        /// <updata>null</updata>

        public object ViewSelectBinding(int pk_Task)
        {
            return Rdl.ViewSelectBinding(pk_Task);
        }

        /// <summary>
        /// 根据Title查询数据
        /// </summary>
        /// <param name="id">Title</param>
        /// <returns>任务列表</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/11</create>
        /// <updata>null</updata> 

        public Dictionary<string, object> TitleSelectTaskList(int page, int limit, int UserId,string Title)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"TaskList",Rdl.TitleSelectTaskList(UserId,Title).Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.TitleSelectTaskList(UserId,Title).Count() }
            };
            return dt;
        }

        /// <summary>
        /// 下拉框绑定
        /// </summary>
        /// <param name="id">状态下拉框</param>
        /// <returns>修改和增加页面里的下拉框</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/9</create>
        /// <updata>null</updata>

        public IEnumerable<Sys_TypeID> SelectTypeBinding()
        {
            return Rdl.SelectTypeBinding();//调用DAL层的SelectTypeBinding方法
        }

        /// <summary>
        /// 下拉框绑定
        /// </summary>
        /// <param name="id">状态下拉框</param>
        /// <returns>修改和增加页面里的下拉框</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/9</create>
        /// <updata>null</updata>

        public IEnumerable<Sys_StatusID> SelectStatusBinding()
        {
            return Rdl.SelectStatusBinding();//调用DAL层的SelectStatusBinding方法
        }

        /// <summary>
        /// 增加和修改
        /// </summary>
        /// <param name="id">pk_Task</param>
        /// <returns>修改和增加页面</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/10</create>
        /// <updata>null</updata>

        public bool EditTaskList(Task_List tl,string type,string CheckDt,int pk_User)
        {
            Rdl.EditTaskList(tl,type,CheckDt,pk_User);
            return Rdl.SaveChanges();
        }

        /// <summary>
        /// 修改保存
        /// </summary>
        /// <param name="id">pk_Task</param>
        /// <returns>查看页面保存</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/21</create>
        /// <updata>null</updata>

        public bool TaskViewUpdata(Task_List tl,string sumUserFeedback)
        {
            Rdl.TaskViewUpdata(tl, sumUserFeedback);
            return Rdl.SaveChanges();
        }

        /// <summary>
        /// 查询接收人 查询用户表
        /// </summary>
        /// <param name="id"></param>
        /// <returns>新增接收人</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/11</create>
        /// <updata>null</updata>

        public Dictionary<string, object> UserList(int page, int limit)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"UserList",Rdl.UserList().Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.UserList().Count() }
            };
            return dt;
        }

        public Dictionary<string, object> UserSelectList(int page, int limit, string UserSelect)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"UserList",Rdl.UserSelectList(UserSelect).Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.UserSelectList(UserSelect).Count() }
            };
            return dt;
        }

        /// <summary>
        /// 获取当前登录用户接收的任务页面信息
        /// </summary>
        /// <param name="id">当前登录的用户id</param>
        /// <returns>任务列表</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/11</create>
        /// <updata>null</updata>

        public Dictionary<string, object> ReceiveTaskList(int page, int limit, string UserId)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"TaskList",Rdl.ReceiveTaskList(UserId).Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.ReceiveTaskList(UserId).Count() }
            };
            return dt;
        }

        /// <summary>
        /// 根据Title查询数据
        /// </summary>
        /// <param name="id">Title</param>
        /// <returns>任务列表</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/11</create>
        /// <updata>null</updata> 

        public Dictionary<string, object> TitleSelectMyTaskList(int page, int limit, string UserId, string Title)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"TaskList",Rdl.TitleSelectMyTaskList(UserId,Title).Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.TitleSelectMyTaskList(UserId,Title).Count() }
            };
            return dt;
        }


        public override void SetDal()
        {
            Dal = Task_ListService;
        }
    }
}
